package cn.hdy.org.service.impl;

import cn.hdy.base.service.impl.BaseServiceImpl;
import cn.hdy.base.util.PageList;
import cn.hdy.org.domain.Shop;
import cn.hdy.org.mapper.ShopMapper;
import cn.hdy.org.query.ShopQuery;
import cn.hdy.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@CacheConfig(cacheNames = "shop")
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    @CacheEvict(key = "'List'")
    public void add(Shop shop) {
        shop.setRegisterTime(new Date());
        shopMapper.add(shop);
    }

    @Override
    @CacheEvict(key = "'List'")
    public void del(Long id) {
        shopMapper.del(id);
    }

    @Override
    @CacheEvict(key = "'List'")
    public void patchDel(Long[] ids) {
        shopMapper.patchDel(ids);
    }

    @Override
    @CacheEvict(key = "'List'")
    public void update(Shop shop) {
        shop.setRegisterTime(new Date());
        shopMapper.update(shop);
    }

    @Override
    @Cacheable(key = "'List'")
    public List<Shop> findAll() {
        return shopMapper.findAll();
    }



    @Override
    public PageList<Shop> queryPage(ShopQuery query) {
        PageList<Shop> pageList = new PageList<>();
        Long count = shopMapper.queryCount(query);
        if (count == null || count == 0) {
            return pageList;
        }
        List<Shop> shopList = shopMapper.queryData(query);
        pageList.setData(shopList);
        pageList.setTotals(count);
        return pageList;
    }
}
